//
//  CenterOverviewMassge.m
//  YZZX
//
//  Created by Easaa on 15/5/25.
//  Copyright (c) 2015年 Easaa. All rights reserved.
//

#import "CenterOverviewMassge.h"
@implementation CenterOverviewMassge
{
    HXHttpRequest           *_httpRequest;              //发起请求
    UIWebView               *_massgeWebView;
    float _textFontSize;
    
}

- (id)initWithFram: (CGRect)frame CategoryModel:(CategoryDataModel *)model
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.modelCategory = model;
        self.DataModel = [[NSMutableArray alloc]init];
        [self changView];
        
    }
    return self;
}


- (void)changView
{
    NSDictionary* dicParams1 = [NSDictionary dictionaryWithObjectsAndKeys:
                                [XSZ_UICommon useridChangUaerdfLoginBoolString],    @"user_id",
                                @"1",    @"site_id",
                                self.modelCategory.cate_id,    @"cate_id",
                                [NSNumber numberWithInteger:1],  @"page_no",
                                [NSNumber numberWithInteger:20], @"page_size",nil];
    
    if (_httpRequest == nil)
    {
        _httpRequest = [[HXHttpRequest alloc] init];
        _httpRequest.delegate = self;
        
        
        
    }
    [_httpRequest requestForParams:dicParams1 andMethod:YZ_ARTICLE_LIST2 andTag:1023];//@"system.time"];//
    
    
}

- (void)permissionsView
{
    
    YZCellMassgeModel *cellmodel = self.DataModel[0];
    NSMutableArray *arrykey = [[NSMutableArray alloc]init];
    [arrykey addObject:cellmodel.id_massge];
    
    
    //列表请求
    NSDictionary* dicParams = [NSDictionary dictionaryWithObjectsAndKeys:
                               [XSZ_UICommon useridChangUaerdfLoginBoolString],    @"user_id",
                               @"1",    @"site_id",
                               arrykey, @"ids"
                               ,nil];
    
    
    if (_httpRequest == nil)
    {
        _httpRequest = [[HXHttpRequest alloc] init];
        _httpRequest.delegate = self;
        
        
        
    }
    [_httpRequest requestForParams:dicParams andMethod:YZ_ARTICLE_QUERY andTag:1001];//@"system.time"];//@"category.list"];
    
    
    
}




#pragma mark - HXHttpRequestDelegate  代理

- (void)requestFinished:(NSString *)responseString andStatusCode:(int)statusCode andTag:(NSInteger)tag
{
    
    //tableview列表数据
    if(tag == 1023)
    {
        
        NSDictionary *dic = [[NSDictionary alloc]init];
        dic = [JsonUtil jsonToDic:responseString];
        
        if ([dic[@"data"] isEqual:[NSNull null]])
        {
            return;
        }
        
        NSString * strs = dic[@"data"];
        
        NSDictionary *dics =[JsonUtil jsonToDic:strs];
        
        NSArray *arryy =(NSArray *)dics;
        
        //NSLog(@"-----------> %@",arryy);
        //NSMutableArray *arryData = [[NSMutableArray alloc]init];
        
        //在刷新后清空上次数据
        [self.DataModel removeAllObjects];
        
        
        for (NSDictionary *dicuu in arryy) {
            
            
            YZCellMassgeModel *cellmodel =[[YZCellMassgeModel alloc]init];
            
            cellmodel.CateId = [dicuu objectForKey:@"CateId"];
            cellmodel.Image = [dicuu objectForKey:@"Image"];
            cellmodel.ReleaseDate= [dicuu objectForKey:@"ReleaseDate"];
            cellmodel.Subtitle = [dicuu objectForKey:@"Subtitle"];
            cellmodel.Summary= [dicuu objectForKey:@"Summary"];
            cellmodel.Title = [dicuu objectForKey:@"Title"];
            cellmodel.id_massge = [dicuu objectForKey:@"id"];
            
            [self.DataModel addObject:cellmodel];
            
        }
        
        [self permissionsView];
        
        
    }else if (tag == 1001)
    {
        
        
        
        NSDictionary *dic = [[NSDictionary alloc]init];
        dic = [JsonUtil jsonToDic:responseString];
        
        // NSLog(@"---------------->>>> \n%@",dic);
        
        NSString * strs = dic[@"data"];
        
        NSDictionary *dics =[JsonUtil jsonToDic:strs];
        
        
        NSArray *arryy =(NSArray *)dics;
        
        // NSLog(@"---------00------->>>> %@",arryy);
        
        NSDictionary *dicuu = [arryy objectAtIndex:0];
        
        
        
        self.Content=[dicuu objectForKey:@"Content"];
        
        [self ceartUIView];
        
    }
}

#pragma mark  HXHttpRequest - 请求代理，，错误代理
- (void)requestFailed:(NSError *)error andTag:(NSInteger)tag
{
    
    
}
- (void)ceartUIView
{
    
    _massgeWebView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, Dev_ScreenWidth, Dev_ScreenHeight-64-48-40)];
    _massgeWebView.delegate=self;
    
    //MassgeWebView.dataDetectorTypes=UIDataDetectorTypeNone;
    //MassgeWebView.frame= CGRectMake(0, 0, Dev_ScreenWidth, 0);
    // MassgeWebView.scrollView.delegate = self;
    _massgeWebView.scrollView.alwaysBounceVertical = NO;
    _massgeWebView.scrollView.bounces = NO;
    _massgeWebView.scrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:_massgeWebView];
    
    //********************************************字体大小样式设置****************************************
    
    
    //拿到设置字体大小设置
    NSUserDefaults *UserDefaultSize =[NSUserDefaults standardUserDefaults];
    _textFontSize = [UserDefaultSize floatForKey:YZZX_Font_Size];
    _textFontSize = 16;
    
    NSString *temstr=@"<style type=\"text/css\">img{max-width:100%;height:auto;} </style>";//只要是img标签都限定大小
    
    NSString *fontString = [NSString stringWithFormat:@"<style type=\"text/css\">*{-webkit-user-select: none;line-height:30px;font-size:%fpx; } </style>", _textFontSize];
    
    NSString *htmlString1 = [NSString stringWithFormat:@"%@%@%@",temstr, fontString, self.Content];//设置大小
    // [_contentWebView loadHTMLString:htmlString1 baseURL:nil]
    
    [_massgeWebView loadHTMLString:htmlString1 baseURL:[NSURL URLWithString:@"http://www.hellomommy.cn/"]];
    
    //     ScrollBackground.contentSize = CGSizeMake(Dev_ScreenWidth, Dev_ScreenHeight-64);
    
    //********************************************字体大小样式设置****************************************
    

    
}



- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
    
    NSString *htmlHeight = [_massgeWebView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];
    //设置高度
    _massgeWebView.scrollView.contentSize =CGSizeMake(Dev_ScreenWidth,[htmlHeight floatValue]);
    
}


@end
